package com.sky.wsp.rabbitmq.exchange;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * direct直连模式的交换机配置,包括一个direct交换机，两个队列，三根网线binding
 */
@Configuration
public class DirectExchangeConfig {
    public static final String EXCHANGE_NAME = "my_direct";
    public static final String QUEUE_NAME_1 = "direct_queue_1";
    public static final String  QUEUE_NAME_2 = "direct_queue_2";

    public static final String  ROUTING_KEY_1 = "TENANT.ADD";
    public static final String  ROUTING_KEY_2 = "TENANT.UPDATE";
    public static final String  ROUTING_KEY_3 = "TENANT.DELETE";

    @Bean
    public DirectExchange directExchange() {
        DirectExchange directExchange = new DirectExchange(EXCHANGE_NAME);
        return directExchange;
    }

    @Bean
    public Queue directQueue1() {
        Queue queue = new Queue(QUEUE_NAME_1);
        return queue;
    }

    @Bean
    public Queue directQueue2() {
        Queue queue = new Queue(QUEUE_NAME_2);
        return queue;
    }

    //3个binding将交换机和相应队列连起来
    @Bean
    public Binding bindingDirect1() {
        Binding binding = BindingBuilder.bind(directQueue1()).to(directExchange()).with(ROUTING_KEY_1);
        return binding;
    }

    @Bean
    public Binding bindingDirect2() {
        Binding binding = BindingBuilder.bind(directQueue2()).to(directExchange()).with(ROUTING_KEY_2);
        return binding;
    }

    @Bean
    public Binding bindingDirect3() {
        Binding binding = BindingBuilder.bind(directQueue2()).to(directExchange()).with(ROUTING_KEY_3);
        return binding;
    }


}
